using Microsoft.AspNetCore.Mvc;
using ZR.Model.Dto;
using ZR.Service.Business.IBusinessService;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;

//创建时间：2024-09-29
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    ///  订单详情表
    /// </summary>
    [Verify]
    [Route("business/OrderDetailInfo")]
    [ApiExplorerSettings(GroupName = "business")]
    public class OrderDetailInfoController : BaseController
    {
        /// <summary>
        ///  订单详情表接口
        /// </summary>
        private readonly IOrderDetailInfoService _OrderDetailInfoService;

        public OrderDetailInfoController(IOrderDetailInfoService OrderDetailInfoService)
        {
            _OrderDetailInfoService = OrderDetailInfoService;
        }

        /// <summary>
        /// 查询 订单详情表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "orderdetailinfo:list")]
        public IActionResult QueryOrderDetailInfo([FromQuery] OrderDetailInfoQueryDto parm)
        {
            var response = _OrderDetailInfoService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询 订单详情表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "orderdetailinfo:query")]
        public IActionResult GetOrderDetailInfo(int Id)
        {
            var response = _OrderDetailInfoService.GetInfo(Id);

            var info = response.Adapt<OrderDetailInfoDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加 订单详情表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "orderdetailinfo:add")]
        [Log(Title = " 订单详情表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddOrderDetailInfo([FromBody] OrderDetailInfoDto parm)
        {
            var modal = parm.Adapt<OrderDetailInfo>().ToCreate(HttpContext);

            var response = _OrderDetailInfoService.AddOrderDetailInfo(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新 订单详情表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "orderdetailinfo:edit")]
        [Log(Title = " 订单详情表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateOrderDetailInfo([FromBody] OrderDetailInfoDto parm)
        {
            var modal = parm.Adapt<OrderDetailInfo>().ToUpdate(HttpContext);
            var response = _OrderDetailInfoService.UpdateOrderDetailInfo(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除 订单详情表
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "orderdetailinfo:delete")]
        [Log(Title = " 订单详情表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteOrderDetailInfo([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_OrderDetailInfoService.Delete(idArr));
        }
    }
}